//
//  RNOLMoneyManagerListCell.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/17.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMoneyManagerListCell.h"


@interface RNOLMoneyManagerListCell()

@property (nonatomic,strong) UILabel *investPlanNameLabel;//投资计划名
@property (nonatomic,strong) UILabel *investMoneyLabel;//投资金额
@property (nonatomic,strong) UILabel *receivableInterestLabel;//应收利息
@property (nonatomic,strong) UILabel *redBagLabel; //使用红包
@property (nonatomic,strong) UILabel *yearInterestLabel; //年化加息


@property (nonatomic,strong) UILabel *investRuleLabel;//投资规则
@property (nonatomic,strong) UILabel *investProportionLabel;//投资比例
@property (nonatomic,strong) UILabel *durationLabel;//时长
@property (nonatomic,strong) UILabel *statusLabel; //投标状态
@property (nonatomic,strong) UILabel *dateLabel; //投标日期

@property (nonatomic,strong) UIView *bottomLineView; //分隔线

@end


@implementation RNOLMoneyManagerListCell


- (UILabel *)investPlanNameLabel{
    if (!_investPlanNameLabel) {
        _investPlanNameLabel = [RNOLUnitTool createLabelWithText:@"投资计划20171119007" textColor:kTextColor fontSize:12];
    }
    return _investPlanNameLabel;
}

- (UILabel *)investMoneyLabel{
    if (!_investMoneyLabel) {
        _investMoneyLabel = [RNOLUnitTool createLabelWithText:@"投标金额:500.00元" textColor:kTextLightColor fontSize:12];
    }
    return _investMoneyLabel;
}

- (UILabel *)receivableInterestLabel{
    if (!_receivableInterestLabel) {
        _receivableInterestLabel = [RNOLUnitTool createLabelWithText:@"应收利息：3.96元" textColor:kTextLightColor fontSize:12];
    }
    return _receivableInterestLabel;
}


- (UILabel *)redBagLabel{
    if (!_redBagLabel) {
        _redBagLabel = [RNOLUnitTool createLabelWithText:@"使用红包：3.96元" textColor:kTextLightColor fontSize:12];
    }
    return _redBagLabel;
}


- (UILabel *)yearInterestLabel{
    if (!_yearInterestLabel) {
        _yearInterestLabel = [RNOLUnitTool createLabelWithText:@"年化加息：0.00%" textColor:kTextLightColor fontSize:12];
    }
    return _yearInterestLabel;
}


- (UILabel *)investRuleLabel{
    if (!_investRuleLabel) {
        _investRuleLabel = [RNOLUnitTool createLabelWithText:@"每月付息 到期还本" textColor:kTextLightGrayColor fontSize:12 textAlignment:NSTextAlignmentRight];
    }
    return _investRuleLabel;
}


- (UILabel *)investProportionLabel{
    if (!_investProportionLabel) {
        _investProportionLabel = [RNOLUnitTool createLabelWithText:@"9.50%" textColor:kTextLightGrayColor fontSize:12 textAlignment:NSTextAlignmentRight];
    }
    return _investProportionLabel;
}

- (UILabel *)durationLabel{
    if (!_durationLabel) {
        _durationLabel = [RNOLUnitTool createLabelWithText:@"一个月" textColor:kTextLightGrayColor fontSize:12 textAlignment:NSTextAlignmentRight];
    }
    return _durationLabel;
}

- (UILabel *)statusLabel{
    if (!_statusLabel) {
        _statusLabel = [RNOLUnitTool createLabelWithText:@"投标中" textColor:kTextLightGrayColor fontSize:12 textAlignment:NSTextAlignmentRight];
    }
    return _statusLabel ;
}

- (UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [RNOLUnitTool createLabelWithText:@"2017-11-18 18:23:00" textColor:kTextLightGrayColor fontSize:12 textAlignment:NSTextAlignmentRight];
    }
    return _dateLabel;
}

- (UIView *)bottomLineView{
    if (!_bottomLineView) {
        _bottomLineView = [[UIView alloc] init];
        _bottomLineView.layer.backgroundColor = [kBgColor CGColor];
        _bottomLineView.alpha = 1;
    }
    return _bottomLineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self setup];
    }
    return self;
}


- (void)setup{
    [self.contentView addSubview: self.investPlanNameLabel];
    [self.contentView addSubview: self.investMoneyLabel];
    [self.contentView addSubview: self.receivableInterestLabel];
    [self.contentView addSubview: self.redBagLabel];
    [self.contentView addSubview: self.yearInterestLabel];
    [self.contentView addSubview: self.investRuleLabel];
    [self.contentView addSubview: self.investProportionLabel];
    [self.contentView addSubview: self.durationLabel];
    [self.contentView addSubview: self.statusLabel];
    [self.contentView addSubview: self.dateLabel];
    [self.contentView addSubview: self.bottomLineView];
    
    
    NSArray *leftViews = @[self.investPlanNameLabel,self.investMoneyLabel,self.receivableInterestLabel,self.redBagLabel,self.yearInterestLabel];
    NSArray *rightViews = @[self.investRuleLabel,self.investProportionLabel,self.durationLabel,self.statusLabel,self.dateLabel];
    CGFloat margin = 20;
    CGFloat kItemWidth = (self.contentView.width - margin*2)/2.0 ;
    CGFloat kItemHeight = 21;
    UIView *lastView = nil;
    for (NSInteger i = 0; i < leftViews.count; i++) {
        UIView *view = leftViews[i];
        if (lastView) {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(lastView.mas_bottom).offset(10);
                make.left.mas_equalTo(margin);
                make.width.mas_equalTo(kItemWidth);
                make.height.mas_equalTo(kItemHeight);
            }];
        }else{
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(margin);
                make.left.mas_equalTo(margin);
                make.width.mas_equalTo(kItemWidth);
                make.height.mas_equalTo(kItemHeight);
            }];
        }
        lastView = view;
    }
    
    lastView = nil;
    for (NSInteger i = 0; i < rightViews.count; i++) {
        UIView *view = rightViews[i];
        if (lastView) {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(lastView.mas_bottom).offset(10);
                make.right.mas_equalTo(self.contentView.mas_right).offset(-margin);
                make.width.mas_equalTo(kItemWidth);
                make.height.mas_equalTo(kItemHeight);
            }];
        }else{
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(margin);
                make.right.mas_equalTo(-margin);
                make.width.mas_equalTo(kItemWidth);
                make.height.mas_equalTo(kItemHeight);
            }];
        }
        lastView = view;
    }
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(8);
        make.left.right.equalTo(self.contentView);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];

}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
